package com.hualan.zhsq.service.impl.information;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.hualan.zhsq.entity.information.BuildingInfo;


import com.hualan.zhsq.mapper.information.BuildingMapper;
import com.hualan.zhsq.service.information.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class BuildingServiceImpl  implements BuildingService {


    @Autowired
    private BuildingMapper buildingMapper;


    @Override
    public int add(BuildingInfo buildingInfo) {
        return buildingMapper.insert(buildingInfo);
    }

    @Override
    public int edit(BuildingInfo buildingInfo) {
        return buildingMapper.updateById(buildingInfo);
    }

    @Override
    public int remove(Integer id) {
        return buildingMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return buildingMapper.deleteByIds(Arrays.asList(ids));
    }

    @Override
    public List<BuildingInfo> find() {
        Page<BuildingInfo> buildingInfoPage = buildingMapper.select(null, null);
        return buildingInfoPage.getRecords();
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param buildingInfo
     * @return
     */
    @Override
    public Map<String,Object> findPage(Integer pageNum, Integer pageSize, BuildingInfo buildingInfo) {

        Page<BuildingInfo> page = new Page<>(pageNum,pageSize);
        Page<BuildingInfo> buildingInfoPage = buildingMapper.select(page, buildingInfo);


        //总记录数
        long total = buildingInfoPage.getTotal();
        //总页数
        long pages = buildingInfoPage.getPages();
        List<BuildingInfo> buildingInfos = buildingInfoPage.getRecords();


        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("pages",pages);
        map.put("list",buildingInfos);
        return map;
    }

    @Override
    public BuildingInfo findById(Integer id) {
        return null;
    }
}
